<template>
  <base-panel>
    <top-simple-search @searchFun="query">
      <el-form-item label="" >
      <el-input v-model="searchParams.creator_name" size="small" :style="{width: '200px'}" placeholder="请输入申请人" clearable></el-input>
      </el-form-item>
      <el-form-item label="" >
      <el-date-picker
        v-model="selectDate"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        size="small"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
        end-placeholder="结束日期">
      </el-date-picker>
      </el-form-item>
      <el-form-item label="" >
      <dept-select-tree v-model="searchParams.dept_id" size="small" placeholder="请选择申请部门" dept-type="all" :appendToBody="true" zIndex="2100"  :disable-branch-nodes="true"></dept-select-tree>
      </el-form-item>
      <el-form-item label="" >
        <dept-select-tree v-model="searchParams.workflow" :disable-branch-nodes="true" placeholder="请选择工作流"  v-bind="$attrs" dept-type="other" :all-dept-list="workflowsList" v-if="loading" style="width: 200px;" size="small"></dept-select-tree>
      </el-form-item>
      <el-form-item label="" >
      <el-input placeholder="当前处理人" v-model="searchParams.participant" size="small" style="width: 200px;" clearable></el-input>
      </el-form-item>
    </top-simple-search>
    <simple-table ref="myTable" size="mini">
      <my-table-column label="工作流名称" align="center" prop="work_name"/>
      <my-table-column label="标题" align="center"  prop="title" min-width="200"></my-table-column>
      <my-table-column label="申请部门" align="center" prop="dept_name"></my-table-column>
      <my-table-column label="申请人" align="center" prop="creator_name"></my-table-column>
      <el-table-column align="left" prop="is_edit" label="是否可编辑" width="100">
        <template slot-scope="{row}">
          <my-switch @change="changeEdit" handle="ganyu" :id="row.id" :switch-value="row.is_edit"></my-switch>
        </template>
      </el-table-column>      <my-table-column label="当前处理人" align="center" prop="participant"></my-table-column>
      <my-time-column label="创建时间" align="center" prop="gmt_created" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80" fixed="right">
        <template slot-scope="{row}">
          <my-button handle="ganyu" @click="showInterveneDialog(row)">干预</my-button>
        </template>
      </el-table-column>
    </simple-table>
    <intervene-dialog v-if="interveneVisible" :visible.sync="interveneVisible" :row="currRow" @reloadList="getList"></intervene-dialog>
  </base-panel>
</template>
<script>
  import simpleTable from '@/mixins/SimpleTable'
  import MyTimeColumn from '@/components/TableColumn/MyTimeColumn'
  import MySwitchColumn from '@/components/TableColumn/MySwitchColumn'
  import MyDictColumn from '@/components/TableColumn/MyDictColumn'
  import MyTableColumn from '../../../../components/TableColumn/MyTableColumn'
  import InterveneDialog from './InterveneDialog'
  import DeptSelectTree from '@/components/Common/DeptSelectTree'
  import SelectTree from '../../../../components/Common/SelectTree'
  import common from "@/api/common/index"
  import MySwitch from "../../../../components/Common/MySwitch";
  // 获取登录用户信息
  export default {
    name:"userTable",
    components: {MySwitch, SelectTree, DeptSelectTree, InterveneDialog, MyTableColumn, MyDictColumn, MySwitchColumn, MyTimeColumn },
    mixins: [simpleTable],
    data() {
      return {
        interveneVisible: false,
        searchParams:{creator_name:"",starttime:"",endtime:"",search_value:"",dept_id:undefined,participant:undefined,workflow:undefined},
        selectDate:[],
        workflowsList:[],
        loading:false
      }
    },
    created() {
      this.getWorkflowsSimple()
    },
    methods: {
      changeEdit(obj){
        common.setTicketsEdit(obj.id,{"is_edit":obj.value}).then(res=>{
          this.msgSuccess(res.msg);
        })
      },
      showInterveneDialog(row){
        this.currRow = row
        this.interveneVisible = true
      },
      query(queryData) {
        this.searchParams.search_value = queryData
        if(this.selectDate){
          this.searchParams.starttime = this.selectDate[0]
          this.searchParams.endtime = this.selectDate[1]
        }else{
          this.searchParams.starttime = ""
          this.searchParams.endtime = ""
        }
        this.$refs["myTable"].searchList(this.searchParams);
      },
      getWorkflowsSimple(){
        common.getWorkflowsSimple().then(res=>{
          this.workflowsList = res.data;
          this.loading = true
        })
      }
    }
  }
</script>
